package org.csu.zhangdian.controller;

import org.csu.zhangdian.domain.Account;
import org.csu.zhangdian.domain.Sale;
import org.csu.zhangdian.domain.Store;
import org.csu.zhangdian.service.SaleService;
import org.csu.zhangdian.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/Store/")
@SessionAttributes("store")
public class StoreController {
    @Autowired
    private StoreService storeService;

    @Autowired
    private SaleService saleService;


    //展示店铺名字和地址
    @RequestMapping("manage")
    public String manage(Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        Account account = (Account) session.getAttribute("account");
        Store store = storeService.getSA(account.getUsername());
        model.addAttribute("address", store.getAddress());
        model.addAttribute("storeName",store.getStoreName());
        model.addAttribute("username",store.getUsername());
        model.addAttribute("duty",store.getDuty());
//        model.addAttribute("store",store);
        Sale sale = saleService.getSaleByBranch_no(store.getStoreNo());
        model.addAttribute("data0",sale.getJanuary());
        model.addAttribute("data1",sale.getFebruary());
        model.addAttribute("data2",sale.getMarch());
        model.addAttribute("data3",sale.getApril());
        model.addAttribute("data4",sale.getMay());
        model.addAttribute("data5",sale.getJune());
        model.addAttribute("data6",sale.getJuly());
        model.addAttribute("data7",sale.getAugust());
        model.addAttribute("data8",sale.getSeptember());
        model.addAttribute("data9",sale.getOctober());
        model.addAttribute("data10",sale.getNovember());
        model.addAttribute("data11",sale.getDecember());

        return "store/specificStore";

    }

    @RequestMapping("compare")
    public String compare(Model model){
        Sale sale10 = saleService.getSaleByBranch_no(1);
        model.addAttribute("data10",sale10.getJanuary());
        model.addAttribute("data11",sale10.getFebruary());
        model.addAttribute("data12",sale10.getMarch());
        model.addAttribute("data13",sale10.getApril());
        model.addAttribute("data14",sale10.getMay());
        model.addAttribute("data15",sale10.getJune());
        model.addAttribute("data16",sale10.getJuly());
        model.addAttribute("data17",sale10.getAugust());
        model.addAttribute("data18",sale10.getSeptember());
        model.addAttribute("data19",sale10.getOctober());
        model.addAttribute("data110",sale10.getNovember());
        model.addAttribute("data111",sale10.getDecember());
        Sale sale20 = saleService.getSaleByBranch_no(2);
        model.addAttribute("data20",sale20.getJanuary());
        model.addAttribute("data21",sale20.getFebruary());
        model.addAttribute("data22",sale20.getMarch());
        model.addAttribute("data23",sale20.getApril());
        model.addAttribute("data24",sale20.getMay());
        model.addAttribute("data25",sale20.getJune());
        model.addAttribute("data26",sale20.getJuly());
        model.addAttribute("data27",sale20.getAugust());
        model.addAttribute("data28",sale20.getSeptember());
        model.addAttribute("data29",sale20.getOctober());
        model.addAttribute("data210",sale20.getNovember());
        model.addAttribute("data211",sale20.getDecember());
        Sale sale30 = saleService.getSaleByBranch_no(3);
        model.addAttribute("data30",sale30.getJanuary());
        model.addAttribute("data31",sale30.getFebruary());
        model.addAttribute("data32",sale30.getMarch());
        model.addAttribute("data33",sale30.getApril());
        model.addAttribute("data34",sale30.getMay());
        model.addAttribute("data35",sale30.getJune());
        model.addAttribute("data36",sale30.getJuly());
        model.addAttribute("data37",sale30.getAugust());
        model.addAttribute("data38",sale30.getSeptember());
        model.addAttribute("data39",sale30.getOctober());
        model.addAttribute("data310",sale30.getNovember());
        model.addAttribute("data311",sale30.getDecember());
        return "store/compare";
    }

    @RequestMapping("store1")
    public String store1(Model model, HttpServletRequest request){
        Sale sale1 = saleService.getSaleByBranch_no(1);
        model.addAttribute("data10",sale1.getJanuary());
        model.addAttribute("data11",sale1.getFebruary());
        model.addAttribute("data12",sale1.getMarch());
        model.addAttribute("data13",sale1.getApril());
        model.addAttribute("data14",sale1.getMay());
        model.addAttribute("data15",sale1.getJune());
        model.addAttribute("data16",sale1.getJuly());
        model.addAttribute("data17",sale1.getAugust());
        model.addAttribute("data18",sale1.getSeptember());
        model.addAttribute("data19",sale1.getOctober());
        model.addAttribute("data110",sale1.getNovember());
        model.addAttribute("data111",sale1.getDecember());

        return "store/store1";
    }

    @RequestMapping("store2")
    public String store2(Model model){
        Sale sale2 = saleService.getSaleByBranch_no(2);
        model.addAttribute("data20",sale2.getJanuary());
        model.addAttribute("data21",sale2.getFebruary());
        model.addAttribute("data22",sale2.getMarch());
        model.addAttribute("data23",sale2.getApril());
        model.addAttribute("data24",sale2.getMay());
        model.addAttribute("data25",sale2.getJune());
        model.addAttribute("data26",sale2.getJuly());
        model.addAttribute("data27",sale2.getAugust());
        model.addAttribute("data28",sale2.getSeptember());
        model.addAttribute("data29",sale2.getOctober());
        model.addAttribute("data210",sale2.getNovember());
        model.addAttribute("data211",sale2.getDecember());

        return "store/store2";
    }

    @RequestMapping("store3")
    public String store3(Model model){
        Sale sale3 = saleService.getSaleByBranch_no(3);
        model.addAttribute("data30",sale3.getJanuary());
        model.addAttribute("data31",sale3.getFebruary());
        model.addAttribute("data32",sale3.getMarch());
        model.addAttribute("data33",sale3.getApril());
        model.addAttribute("data34",sale3.getMay());
        model.addAttribute("data35",sale3.getJune());
        model.addAttribute("data36",sale3.getJuly());
        model.addAttribute("data37",sale3.getAugust());
        model.addAttribute("data38",sale3.getSeptember());
        model.addAttribute("data39",sale3.getOctober());
        model.addAttribute("data310",sale3.getNovember());
        model.addAttribute("data311",sale3.getDecember());

        return "store/store3";
    }

}
